﻿Imports System.Data
Imports System.Data.SqlClient
Public Class ItensVendaDAL

    Function LocalizarServicos(ByVal codigo As Integer) As DataTable
        Dim tab As DataTable
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            ' cmd.CommandText = "select s.pro_codigo,s.pro_descricao,s.pro_precocusto,s.pro_duracao from Vendas.Ofi_ItensAgendamento a inner join vw_estservico s on s.pro_codigo=a.pro_codigo  where " & _
            '    "age_codigo = @codigo"
            cmd.CommandText = "select * from Vendas.Ofi_ItensAgendamento where " & _
                "age_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = codigo
            tab = objconexao.retdadosTab(cmd)
        Catch ex As Exception
            Throw New Exception("", ex)
        Finally
            cmd = Nothing
        End Try
        Return tab
    End Function

    Function ExcluirServicos(ByVal ite_codigo As Integer) As Integer
        Dim ret As Integer
        Dim cmd As SqlCommand
        Try
            cmd = New SqlCommand
            cmd.CommandText = "delete from Vendas.Ofi_ItensAgendamento where " & _
                "age_codigo = @codigo"
            cmd.Parameters.Add(New SqlParameter("@codigo", SqlDbType.Int)).Value = ite_codigo

            ret = objconexao.executaCmd(cmd)
        Catch ex As Exception
            Throw New Exception("", ex)
        Finally
            cmd = Nothing
        End Try
        Return ret
    End Function

    Function InserirServicos(ByVal AgeCodigo As Integer, ByVal ProCodigo As Integer) As Integer

        Dim cmd As SqlCommand
        Dim Ret As Integer
        Try
            cmd = New SqlCommand
            cmd.CommandText = "insert into Vendas.Ofi_ItensAgendamento(age_codigo, pro_codigo) values (@agecodigo, @procodigo)"
            cmd.Parameters.Add(New SqlParameter("@agecodigo", SqlDbType.Int)).Value = AgeCodigo
            cmd.Parameters.Add(New SqlParameter("@procodigo", SqlDbType.Int)).Value = ProCodigo
            Ret = objconexao.executaCmd(cmd)
        Catch ex As Exception
            Throw New Exception("Erro. ", ex)
        Finally
            cmd = Nothing
        End Try
        Return Ret
    End Function

End Class
